import time
from selenium import webdriver
from selenium.webdriver.common.by import By
# from webdriver_manager.chrome import ChromeDriverManager


# driver = webdriver.Chrome("C:\Program Files\driver\chromedriver.exe")
# driver = webdriver.Chrome(ChromeDriverManager().install())

# 初始化浏览器对象
driver = webdriver.Chrome()
driver.maximize_window()
# time.sleep(2)

# # 获取浏览器尺寸
# print(driver.get_window_size())
#
# # 浏览器页面最大化
# driver.maximize_window()
#
# print(driver.get_window_size())
# time.sleep(2)
#
# # 设置浏览器尺寸
# driver.set_window_size(500, 500)
# print(driver.get_window_size())

# driver.get('https://www.baidu.com')

# # 获取浏览器位置
# print(driver.get_window_position())
#
# time.sleep(2)
#
# # 设置浏览器位置
# driver.set_window_position(500, 400)
# print(driver.get_window_position())
# time.sleep(2)
# 获取页面
driver.get("https:\\www.baidu.com")
time.sleep(3)

# # 刷新页面
# driver.refresh()

# # # 定位百度输入框元素-直接调用型，使用css选择器
# # element_input= driver.find_element_by_css_selector("input[id=kw]")
# # By定位
# element_input = driver.find_element(By.CSS_SELECTOR, "input[id=kw]")
# # 输入框内输入：坚果
# element_input.send_keys("坚果")
# time.sleep(2)
# # # 定位百度一下按钮元素-直接调用型，使用xpath定位
# # element_button = driver.find_element_by_xpath("//input[@id='su']")
# # BY定位
# element_button = driver.find_element(By.XPATH, "//input[@id='su']")
# # 点击-百度一下
# element_button.click()
# time.sleep(2)

# # 回退页面
# driver.back()
# time.sleep(2)
#
# # 页面前进
# driver.forward()

# 定位一组元素，返回一个列表，列表中每个元素都是一个元素对象
# elements = driver.find_elements(By.CSS_SELECTOR, "input")
# print(elements)

# # 输入坚果
# driver.find_element_by_id('kw').send_keys('坚果')
# time.sleep(2)
# # 清空输入框
# driver.find_element_by_id('kw').clear()
# # 点击-百度一下
# driver.find_element_by_id('su').click()
# driver.find_element_by_id('su').submit()
# time.sleep(5)
# driver.close()

# 定位【设置】元素
element_setting = driver.find_element(By.CSS_SELECTOR, "#s-usersetting-top")
print("元素文本值为：", element_setting.text)
# 定位【百度一下】元素
element_button = driver.find_element(By.CSS_SELECTOR, "#su")
print("百度一下元素的value值为：", element_button.get_attribute("value"))
print("百度一下元素的type值为：", element_button.get_attribute("type"))
print("百度一下元素的尺寸为：", element_button.size)
print(element_button.is_displayed())
driver.quit()